#!/bin/bash

prog=/Zdata/wwwroot/xata_s/src/server.php

start(){
        echo "正在启动服务...."
        php $prog
        echo "$prog 启动完成"
}
stop(){
        echo "正在停止服务...."
        pid=`cat /Zdata/wwwroot/xata_s/src/server.pid`
        if [ $pid ] && [ $pid -gt 0 ];then
            kill $pid
            # rm -f /Zdata/wwwroot/xata_s/server.pid
            echo "$prog 服务已停止"
        else
            echo "$prog 服务已经停止"
        fi
}
status(){
        count=`ps -ef |grep $prog |grep -v "grep"|wc -l`
        if [ $count -gt 0 ];then
            echo "$prog 服务正在运行"
        else
            echo "$prog 服务已经停止"
        fi
}
restart(){
        stop
        sleep 1 #延迟1秒
        start
}

case "$1" in
"start")
        start
        ;;
"stop")
        stop
        ;;
"status")
        status
        ;;
"restart")
        restart
        ;;
*)
        echo "用法：$0 start|stop|status|restart"
        ;;
esac


